﻿#include "unlockwidget.h"

QUnLockWidget::QUnLockWidget(QWidget *parent) : QWidget(parent)
{
//    _cmdMap[0x85] = "编码器主份加电";
//    _cmdMap[0x86] = "编码器备份加电";
//    _cmdMap[0x87] = "绕组主份加电";
//    _cmdMap[0x88] = "绕组备份加电";
    _cmdMap[0x8A] = "解锁1加电";
    _cmdMap[0x8B] = "解锁2加电";

    InitUI();

    connect(_pSetParamButton,&QPushButton::clicked,this,&QUnLockWidget::onSetParamButtonClicked);

}

/**
* @brief
* @note
*
*/
void QUnLockWidget::InitUI()
{
    this->setStyleSheet("QLabel{font-family: 'Microsoft YaHei';}");

    _pTimeEdit = new QLineEdit(this);
    QUIQss::setTxtQss(_pTimeEdit, "#DCE4EC", "#1ABC9C");

    _pCmdComBox = new QComboBox(this);
    _pCmdComBox->setMinimumHeight(30);
    for(int key:_cmdMap.keys())
    {
        QString sButtonName = _cmdMap.value(key);
        _pCmdComBox->addItem(sButtonName);
    }


    _pSetParamButton = new QPushButton("解锁",this);
    QUIQss::setBtnQss(_pSetParamButton,"#1ABC9C", "#E6F8F5", "#2EE1C1", "#FFFFFF", "#16A086", "#A7EEE6");

    QLabel* pLabel1= new QLabel(this);
    pLabel1->setText("解锁指令");
    QLabel* pLabel2= new QLabel(this);
    pLabel2->setText("解锁时间");

    QGridLayout* playout = new QGridLayout(this);

    int nRow = 0;

    playout->addWidget(pLabel1,nRow,0,1,1);
    playout->addWidget(_pCmdComBox,nRow,1,1,2);
    nRow++;

    playout->addWidget(pLabel2,nRow,0,1,1);
    playout->addWidget(_pTimeEdit,nRow,1,1,2);
    nRow++;

    playout->addWidget(_pSetParamButton,nRow,1,1,1);
    nRow++;
}

/**
* @brief
* @note
*
*/
void QUnLockWidget::onSetParamButtonClicked()
{
    float lfvalue = _pTimeEdit->text().toFloat();
    int l_cmd_id = _cmdMap.keys()[_pCmdComBox->currentIndex()];

    int i32value = lfvalue*10.0;

    emit signal_unlockcmd(l_cmd_id,i32value);
}
